package com.itheima.d1_thread_api;

/**
 * 目标：掌握Thread的常用方法。
 */
public class ThreadTest1 {
    public static void main(String[] args){
       //想要获取执行main方法的线程名称、
        Thread thread = Thread.currentThread();
        thread.setName("哈哈哈哈");
        String name = thread.getName();
        System.out.println("name = " + name);

//        MyThread myThread = new MyThread();
//        myThread.start();
//        new myThread("小青").start();
//        System.out.println(myThread.getName());

        new MyThread().start();
        new MyThread().start();
        new MyThread("小青").start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                Thread thread1 = Thread.currentThread();
                System.out.println(thread1.getName()+"内名内部类在运行");
            }
        },"匿名内部类线程").start();

        //lamda
        new Thread(()->{
            Thread thread2 = Thread.currentThread();
            System.out.println(thread2.getName()+"lambda线程在运行");
        },"lambda线程").start();


    }
}
class MyThread extends Thread{
    public MyThread() {
    }

    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(getName()+"在执行");//调用父类getname方法，可以获取线程的名字
    }
}
